<%--@elvariable id="webRoot" type="com.doupi.partner.op.interceptor.OpFilter"--%>
<%--@elvariable id="type" type="com.doupi.partner.op.controller.business.BusinessController.index"--%>

<%@ page language="java" pageEncoding="UTF-8" %>
<%@ include file="../common/tags.jsp" %>

<!DOCTYPE html>
<html>
<head lang="en">
    <%@include file="../common/assets.jsp" %>
</head>
<body>
<!-- header -->
<%@include file="../common/header.jsp" %>

<!-- main start -->
<div class="am-cf admin-main">
    <!-- sidebar start -->
    <%@include file="../common/menu.jsp" %>
    <!-- sidebar end -->

    <!-- content start -->
    <div class="admin-content">

        <div class="am-cf am-padding">
            <div class="am-fl am-cf">
                <strong class="am-text-primary am-text-lg">商家管理</strong> /
                <small>
                    <c:choose><c:when test="${type == 1}">直属商家</c:when><c:when
                            test="${type == 2}">二级商家</c:when></c:choose>
                </small>
            </div>
        </div>

        <div class="am-g">

            <div class="am-u-sm-12 am-u-md-3 am-text-left">
                <util:wholePermission name="business:${type}:add">
                    <a href="${webRoot}/business/${type}/edit/0" class="am-btn am-btn-default">添加</a>
                </util:wholePermission>
                <util:logicPermissionTag name="!business:${type}:add"> &nbsp; </util:logicPermissionTag>
            </div>
            <div class="am-u-sm-12 am-u-md-9 am-form-group">
                <div class="am-g">
                    <%--
                    <div class="am-u-sm-12 am-u-md-4">
                         <div class="am-input-group">
                             <span class="am-input-group-label">起始时间</span>
                             <input id='begin_date' type="text" class="am-form-field" readonly="readonly">
                         </div>
                     </div>
                     <div class="am-u-sm-12 am-u-md-4">
                         <div class="am-input-group">
                             <span class="am-input-group-label">终止时间</span>
                             <input id='end_date' type="text" class="am-form-field" readonly="readonly">
                         </div>
                     </div>
                     --%>
                    <div class="am-u-sm-12 am-u-md-4">
                        <div class="am-form-group" style="float: right; width: 200px; margin-right: 5px;">
                            <div class="am-input-group am-input-group-sm">
                                <input type="text" class="am-form-field" id="searchKey" placeholder="请输入营销号">
                                <span class="am-input-group-btn">
                            <button class="am-btn am-btn-default" type="button"
                                    onclick="searchBusiness();">搜索</button>
                        </span>
                            </div>
                        </div>

                        <div class="am-form-group" style="float: right; margin-right:10px">
                            <select data-am-selected="{btnSize: 'sm',btnWidth:100}" id="selectStatus" title="状态">
                                <option value="" selected="selected">全部</option>
                                <option value="0">初始</option>
                                <option value="1">报备</option>
                                <option value="2">已签约</option>
                                <option value="3">已缴费</option>
                                <option value="97">到期</option>
                                <option value="98">上架</option>
                                <option value="99">已下架</option>
                            </select>
                        </div>

                    </div>
                </div>
            </div>
            <div class="am-g">
                <div class="am-u-sm-12">
                    <form class="am-form">
                        <table width="100%"
                                class="am-table am-table-striped am-table-bordered am-table-compact am-text-nowrap"
                                id="list_table">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>名称</th>
                                <th>手机号</th>
                                <th>营销码</th>
                                <th>平台</th>
                                <th>状态</th>
                                <th>加入时间</th>
                                <th>最后更新时间</th>
                                <util:logicPermissionTag name="business:${type}:edit or business:${type}:delete">
                                    <th>操作</th>
                                </util:logicPermissionTag>
                            </tr>
                            </thead>
                            <tbody>
                            </tbody>
                        </table>
                    </form>
                </div>

            </div>
        </div>
    </div>
    <!-- main end -->

    <!-- foot -->
    <%@include file="../common/footer.jsp" %>

    <script type="text/javascript">
        var BUSINESS_TABLE;
        $(function () {
            //表格初始化
            BUSINESS_TABLE = initDataTable(
                {
                    ajax: '${webRoot}/business/${type}/list',
                    columns: [
                        'id',
                        {
                            data: 'administrator',
                            render: function (v) {
                                return v.name;
                            }
                        },
                        {
                            data: 'administrator',
                            render: function (v) {
                                return v.mobile;
                            }
                        },
                        'marketingNumber',
                        {
                            data: 'source',
                            render: function (v) {
                                return {
                                    "1": "逗皮",
                                    "2": "逗米"
                                }[v];
                            }
                        },
                        {
                            data: 'status',
                            render: function (v) {
                                return {
                                    "0": "初始",
                                    "1": "报备",
                                    "2": "已签约",
                                    "3": "已缴费",
                                    "97": "到期",
                                    "98": "上架",
                                    "99": "下架"
                                }[v];
                            }
                        },
                        'createTime',
                        'updateTime'
                        <util:logicPermissionTag name="business:${type}:edit or business:${type}:delete">
                        ,
                        function (v, flag, data) {
                            var html = '<div class="am-btn-group am-btn-group-xs">';
                            <util:wholePermission name="business:${type}:delete">
                            html += '<button type="button" onclick="deleteBusiness(\'' + data.id + '\');" class="am-btn am-btn-default am-btn-xs">删除</button>';
                            </util:wholePermission>
                            <util:wholePermission name="business:${type}:edit">
                            html += '<a href="${webRoot}/business/${type}/edit/' + data.id + '" class="am-btn am-btn-default am-btn-xs am-text-secondary">编辑</a>';
                            </util:wholePermission>
                            html += '</div>';

                            return html;
                        }
                        </util:logicPermissionTag>
                    ]
                }, function () { //搜索参数JSON数据
                    return {
                        status: $('#selectStatus').val(),
                        marketNumber: $('#searchKey').val()/*,
                         startTime: $('#begin_date').val(),
                         endTime: $('#end_date').val()*/
                    };
                });
            /*初始化日期选择插件*/
            /*$('#begin_date, #end_date').datetimepicker({
             locale: 'zh-CN',
             format: 'YYYY-MM-DD HH:mm:ss',
             showTodayButton: true,
             ignoreReadonly: true
             });
             $('#begin_date').on('dp.change', function (e) {
             $('#end_date').data('DateTimePicker').minDate(e.date);
             });
             $('#end_date').on('dp.change', function (e) {
             $('#begin_date').data('DateTimePicker').maxDate(e.date);
             });*/
        });

        //搜索
        function searchBusiness() {
            BUSINESS_TABLE.draw();
        }

        //删除
        function deleteBusiness(id) {
            layer.confirm('确定要删除商家：' + id + '?', {
                title: '删除确认'
            }, function () {
                ajaxRequest({
                    url: '${webRoot}/business/${type}/delete/' + id,
                    method: 'DELETE'
                }, function () {
                    searchBusiness();
                });
            });
        }
    </script>
</body>
</html>